{% extends 'bugs/base.html' %}

{% block content %}


    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                        aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="{% url 'bugs:index' %}">Software Afair Management System</a>
            </div>
        </div>
    </nav>

    <div class="container">
        <form action="/update_demand/" method="post" accept-charset="utf-8" class="form" role="form">
            {% csrf_token %}

            <input type="hidden" name="id" value={{ data.id }}>
            <input type="hidden" name="csrfmiddlewaretoken" value="tcKPX6l1AsO1DFMDs7LUZqCBkKRT7mZP">
            <legend>修改需求</legend>
            <input type="hidden" name="csrfmiddlewaretoken" value="tcKPX6l1AsO1DFMDs7LUZqCBkKRT7mZP">
            {% for data in demand_data %}
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="id_project">专案名称</label>
                    <div class="col-sm-10">
                        <input class="form-control" id="type" name="type" value="{{ data.name }}" readonly>
                    </div>
                </div>

                <br>
                <br>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="id_type">需求种类</label>
                    <div class="col-sm-10">
                        <input class="form-control" id="type" name="type" value="{{ data.require_type }}">
                    </div>
                </div>
                <!--状态-->
                {% if authority == '2' %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="id_version">状态</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="id_state" name="state">
                                <a value="{{ data.state }}">{{ data.state }}</a>
                                <option value="已完成">已完成</option>
                                <option value="验证有误">验证有误</option>
                            </select>
                        </div>
                    </div>
                {% elif authority == '1' %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="id_state">状态</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="id_state" name="state">
                                <p data-value="{{ data.state }}">{{ data.state }}</p>
                                <option value="待验证">待验证</option>
                                <option value="处理中">处理中</option>
                                <option value="已完成">已完成</option>
                            </select>
                        </div>
                    </div>
                    <br>
                {% else %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="id_state">状态</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="id_state" name="state">
                                <option value="带指派">待指派</option>
                                <option value="处理中">处理中</option>
                                <option value="已完成">已完成</option>
                                <option value="待验证">待验证</option>
                                <option value="验证有误">验证有误</option>
                            </select>
                        </div>
                    </div>
                {% endif %}
                <!--紧急程度-->
                {% if authority == '0' %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="id_level">紧急程度</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="id_level" name="level">
                                <a value="{{ data.level }}">{{ data.level }}</a>
                                <option value="低">低</option>
                                <option value="一般">一般</option>
                                <option value="紧急">紧急</option>
                            </select>
                        </div>
                    </div>
                {% else %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="id_level">优先权</label>
                        <div class="col-sm-10">
                            <input class="form-control" id="level" name="level" readonly
                                   value={{ data.level }}>
                        </div>
                    </div>
                    <br>
                    <br>
                {% endif %}
                <br>
                <br>
                <!--难度-->
                {% if authority == '0' or authority == '1' %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="id_difficult">难度</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="id_difficult" name="difficult">
                                <option value="低">低</option>
                                <option value="一般">一般</option>
                                <option value="难">难</option>
                            </select>
                        </div>
                    </div>
                {% endif %}
                <br>
                <!--描述-->
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="id_description">描述</label>
                    <div class="col-sm-10">
                        <input class="form-control" id="description" name="description" readonly
                               value={{ data.description }}>
                    </div>
                </div>
                <!--预计完成日期-->
                {% if authority == '0' or authority == '1' %}
                    {% if data.estime == DateTime.MinValue %}
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="id_estime">预计完成日期</label>
                            <div class="col-sm-10">
                                <input class="" id="id_estime" name="estime" type="datetime-local"
                                       value=""/>
                            </div>
                        </div>
                        <br>
                    {% else %}
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="id_estime">预计完成日期</label>
                            <div class="col-sm-10">
                                <input class="" id="id_estime" name="estime" type=""
                                       value="{{ data.estime | date:" Y-m-d H:i:s" }} "/>
                            </div>
                        </div>
                    {% endif %}
                {% endif %}

                <!--文件补充-->
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="id_description">文件上传</label>
                    <div class="col-sm-10">
                        <input class="form-control" id="id_file" name="file" type="file" multiple="multiple">
                    </div>
                </div>
                <br>
                <br>
                <!--文件下载-->
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="id_description">已上传文件</label>
                    <div class="col-sm-10">
                        <!--<input class="form-control" id="description" name="description" readonly-->
                        <!--value="">-->
                        {% for file in files %}
                            <a id="{{ file.id }}" onclick="download_file(this)">{{ file.name }}</a>
                        {% endfor %}
                    </div>
                </div>
                <!--bug发起人信息-->
                {% for owner in owner_message %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="id_owner">发起人信息</label>
                        <div class="col-sm-10">
                            <input class="" id="owner_c_name" name="owner_c_name" readonly
                                   value={{ owner.c_name }}>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input class="" id="owner_c_phone" name="owner_c_phone" readonly
                                   value={{ owner.phone }}>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input class="" id="owner_c_email" name="owner_c_email" readonly
                                   value={{ owner.email }}>
                        </div>
                    </div>
                {% endfor %}
                <br>
                <!--修改受理人-->
                {% if authority == '0' %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="id_assignee">受理人</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="id_assignee" name="assignee">
                                {% for engineer in engineer_data %}
                                    <option value="{{ engineer.user_id }}">{{ engineer.c_name }}</option>
                                {% endfor %}
                            </select>

                        </div>
                    </div>
                {% elif authority == '1' %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="id_assignee">受理人</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="id_assignee" name="assignee">
                                {% for engineer in engineer_data %}
                                    <option value="{{ engineer.user_id }}">{{ engineer.c_name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                {% endif %}
                <!--受理人信息-->
                {% for assignee in assignee_message %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="id_assignee_message">受理人信息</label>
                        <div class="col-sm-10">
                            <input class="" id="assignee_message_name" name="assignee_message_name" readonly
                                   value={{ assignee.c_name }}>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input class="" id="assignee_message_phone" name="assignee_message_phone" readonly
                                   value={{ assignee.phone }}>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input class="" id="assignee_message_email" name="assignee_message_email" readonly
                                   value={{ assignee.email }}>
                        </div>
                    </div>
                {% endfor %}
                <!--路径-->
                {% for project in project_data %}
                    <br>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="id_path">路径/网址</label>
                        <div class="col-sm-10">
                            <input class="form-control" id="path" name="path" readonly
                                   value={{ project.path }}>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                        </div>
                    </div>
                {% endfor %}
                <br>
                <br>
                {% if message %}
                    <p value="{{ message }}">{{ message }}</p>
                {% endif %}
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <br>
                        <button type="submit" class="btn btn-primary">Submit</button>
                    </div>
                </div>
            {% endfor %}

        </form>
    </div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                </div>
                <div class="modal-body">
                    <img style="width: 100%;" id="big_pic" src="">
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function download_file(e) {
            console.log('this id:', e.id);
            window.location.href = "/download/" + e.id;
        }

    </script>
{% endblock %}
